package com.weitu.risk.service.impl;

import com.weitu.risk.entity.MatrixLevel;
import com.weitu.risk.mapper.MatrixLevelMapper;
import com.weitu.risk.service.MatrixLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MatrixLevelServiceImpl implements MatrixLevelService {
    @Autowired
    private MatrixLevelMapper matrixLevelMapper;

    @Override
    public boolean addOrEditMatrixLevel(Map<String, Object> map) {
        List<MatrixLevel> matrixLevels = this.matrixLevelMapper.queryMatrixLevelByParam(map);
        boolean flag = false;
        if(matrixLevels.size()<1){
            int result = this.matrixLevelMapper.insertMatrixLevel(map);
            if(result>=1){
                flag= true;
            }
        }else{
            map.put("id",matrixLevels.get(0).getId());
            int result = this.matrixLevelMapper.updateMatrixLevel(map);
            if(result>=1){
                flag = true;
            }
        }
        return flag;
    }

    @Override
    public List<MatrixLevel> queryMatrixLevels(Map<String, Object> map) {
        return this.matrixLevelMapper.queryMatrixLevelByParam(map);
    }
}